import * as vscode from 'vscode';
import {authorizationVerification} from "./authorize";

export async function algWorkbench(context: vscode.ExtensionContext) {
    console.log('恭喜你，你的扩展“algWorkbench”现在是活跃的!');

    const provider = new AlgWorkbenchViewProvider(context.extensionUri);
    context.subscriptions.push(
        vscode.window.registerWebviewViewProvider(AlgWorkbenchViewProvider.viewType, provider)
    );

}


class AlgWorkbenchViewProvider implements vscode.WebviewViewProvider {
    public static readonly viewType = 'algWorkbench';
    private webview: vscode.Webview | undefined;

    constructor(private readonly extensionUri: vscode.Uri) {
    }

    public resolveWebviewView(
        webviewView: vscode.WebviewView,
        context: vscode.WebviewViewResolveContext,
        _token: vscode.CancellationToken
    ): void {
        this.webview = webviewView.webview;
        webviewView.webview.options = {
            enableScripts: true,
            localResourceRoots: [this.extensionUri]
        };

        webviewView.webview.html = this.getHtmlForWebview(webviewView.webview);

    }


    private getHtmlForWebview(webview: vscode.Webview): string {

        return `
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>996纯lua引擎-alg工作台</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #1e1e1e;
            color: #d4d4d4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            width: 600px;
            background-color: #252526;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
            border-radius: 8px;
            overflow: hidden;
            font-size: 14px;
        }
        .title {
            text-align: center;
            font-weight: bold;
            font-size: 20px;
            padding: 20px;
            background-color: #007acc;
            color: white;
        }
        .input-group {
            display: flex;
            justify-content: space-between;
            margin: 10px 20px;
        }
        .input-group input {
            flex: 1;
            padding: 10px;
            background-color: #3c3c3c;
            border: 1px solid #555;
            border-radius: 4px;
            color: #d4d4d4;
            margin-right: 10px;
        }
        .input-group button {
            background-color: #007acc;
            border: none;
            padding: 10px;
            border-radius: 4px;
            cursor: pointer;
            color: white;
        }
        .btn-green {
            background-color: #16825d;
            color: white;
            border: none;
            padding: 10px 20px;
            cursor: pointer;
            margin: 20px;
            width: calc(100% - 40px);
            border-radius: 4px;
        }
        .status-bar {
            background-color: #007acc;
            padding: 10px;
            text-align: center;
            margin: 20px;
            border-radius: 4px;
        }
        .button-group {
            display: flex;
            justify-content: space-around;
            margin: 20px;
        }
        .button-group button {
            background-color: #16825d;
            color: white;
            border: none;
            padding: 10px 20px;
            cursor: pointer;
            border-radius: 4px;
            flex: 1;
            margin: 0 10px;
        }
        .log {
            background-color: #1e1e1e;
            color: #00FF00;
            padding: 10px;
            height: 200px;
            overflow-y: auto;
            font-family: monospace;
            margin: 20px;
            border-radius: 4px;
            border: 1px solid #555;
        }
        .footer {
            text-align: center;
            margin-top: 10px;
            padding: 20px;
            background-color: #2d2d2d;
            border-top: 1px solid #555;
        }
        .footer button {
            background-color: #007acc;
            color: white;
            border: none;
            padding: 10px 20px;
            cursor: pointer;
            border-radius: 4px;
            margin: 5px;
        }
        .footer button.red {
            background-color: #d9534f;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="title">996纯lua引擎-alg工作台</div>
        <div class="input-group">
            <input type="text" placeholder="xls|csv目录">
            <button>修改</button>
        </div>
        <div class="input-group">
            <input type="text" placeholder="服务器路径">
            <button>修改</button>
        </div>
        <div class="input-group">
            <input type="text" placeholder="客户端路径">
            <button>修改</button>
        </div>
        <div class="input-group">
            <input type="text" placeholder="alg打包目录">
            <button>修改</button>
        </div>
        <button class="btn-green">xls|csv一键转lua</button>
        <div class="status-bar">
            复制后的xls|csv自定义转换在仿真QFunction.lua中自行处理
        </div>
        <div class="input-group">
            <button style="background-color: #007acc; width: 100%; padding: 10px;">重载仿真QFunction.lua(仅转表数据相关支持)</button>
        </div>
        <div class="button-group">
            <button>最新版本更新</button>
            <button>生产混淆打包</button>
        </div>
        <div class="log">
            <p>14:26:00|alg为所累用框架以及文书辅助工具完全免费收敛的吧尼露子！</p>
            <p>14:26:00|疯叠所有有台单牛收费或尝试赚钱，请前向作家半早登录红会</p>
            <p>14:26:01|仿真程序：开始加载QFunction...</p>
            <p>14:26:01|hello alg.</p>
            <p>14:26:01|[alg-debug]:当前加载服务器路径名称: F:\\996-lua-algMirServerMir200\\Envir\\alg\\dev\\配置</p>
            <p>14:26:01|[alg-debug]:当前加载客户端路径名称: F:\\996-lua-alg\\Client\\dev\\alg\\dev\\config</p>
            <p>14:26:01|[alg-debug]: 检查工具启动成功...</p>
            <p>14:26:14|打包完成时间:5999ms</p>
            <p>14:26:30|打包完成时间:8524ms</p>
        </div>
        <div class="footer">
            QQ群: 436063587 工具免费 ver:2.1.0
        </div>
        <div class="footer">
            <button>访问通用教学</button>
            <button>访问内部教学</button>
            <button class="red">重新启动</button>
        </div>
    </div>
</body>
</html>

`;
    }
}
